home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH13 / EX13_1A.ASM < prev    next >
Encoding:
Assembly Source File  |  1996-02-24  |  2.4 KB  |  106 lines

  1. ; EX13_1a.asm
  2. ;
  3. ; This program copies one file to another using character at a time I/O.
  4. ; It is easy to write, read, and understand, but character at a time I/O
  5. ; is quite slow.  Run this program and time its execution.  Then run the
  6. ; corresponding blocked I/O exercise and compare the execution times of
  7. ; the two programs.
  8.  
  9.         include     stdlib.a
  10.         includelib    stdlib.lib
  11.  
  12.  
  13. dseg        segment    para public 'data'
  14.  
  15. FHndl        word    ?
  16. FHndl2        word    ?
  17. Buffer        byte    ?
  18.  
  19. FName        equ    this word
  20. FNamePtr    dword    FileName
  21.  
  22. Filename    byte    "Ex13_1.in",0
  23. Filename2    byte    "Ex13_1.out",0
  24.  
  25. dseg        ends
  26.  
  27.  
  28. cseg        segment    para public 'code'
  29.         assume    cs:cseg, ds:dseg
  30.  
  31. Main        proc
  32.         mov    ax, dseg
  33.         mov    ds, ax
  34.         mov    es, ax
  35.         meminit
  36.  
  37.         mov    ah, 3dh         ;Open the input file
  38.         mov    al, 0            ; for reading
  39.         lea    dx, Filename        ;Presume DS points at filename
  40.         int    21h            ; segment
  41.         jc    BadOpen
  42.         mov    FHndl, ax        ;Save file handle
  43.  
  44.  
  45.         mov    FName, offset Filename2    ;Set this up in case there
  46.         mov    FName+2, seg FileName2    ; is an error during open.
  47.  
  48.         mov    ah, 3ch         ;Open the output file for writing
  49.         mov    cx, 0            ; with normal file attributes
  50.         lea    dx, Filename2        ;Presume DS points at filename
  51.         int    21h            ; segment
  52.         jc    BadOpen
  53.         mov    FHndl2, ax        ;Save file handle
  54.  
  55. LP:        mov    ah,3fh            ;Read data from the file
  56.         lea    dx, Buffer        ;Address of data buffer
  57.         mov    cx, 1            ;Read one byte
  58.         mov    bx, FHndl        ;Get file handle value
  59.         int    21h
  60.         jc    ReadError
  61.         cmp    ax, cx            ;EOF reached?
  62.         jne    EOF
  63.  
  64.         mov    ah,40h            ;Write data to the file
  65.         lea    dx, Buffer        ;Address of data buffer
  66.         mov    cx, 1            ;Write one byte
  67.         mov    bx, FHndl2        ;Get file handle value
  68.         int    21h
  69.         jc    WriteError
  70.         jmp    LP            ;Read next byte
  71.  
  72. EOF:        mov    bx, FHndl
  73.         mov    ah, 3eh            ;Close file
  74.         int    21h
  75.         jmp    Quit
  76.  
  77. ReadError:    printf
  78.         byte    "Error while reading data from file '%s'.",cr,lf,0
  79.         dword    FileName
  80.         jmp    Quit
  81.  
  82. WriteError:    printf
  83.         byte    "Error while writing data to file '%s'.",cr,lf,0
  84.         dword    FileName2
  85.         jmp    Quit
  86.  
  87. BadOpen:    printf
  88.         byte    "Could not open '%^s'.  Make sure this file is in the ",cr,lf
  89.         byte    "current directory before attempting to run this program again."
  90.         byte    cr,lf,0
  91.         dword    FName
  92.  
  93. Quit:        ExitPgm            ;DOS macro to quit program.
  94. Main        endp
  95.  
  96. cseg            ends
  97.  
  98. sseg        segment    para stack 'stack'
  99. stk        db    1024 dup ("stack   ")
  100. sseg        ends
  101.  
  102. zzzzzzseg    segment    para public 'zzzzzz'
  103. LastBytes    db    16 dup (?)
  104. zzzzzzseg    ends
  105.         end    Main
  106.